package com.miplus.ccrm.core.service.action;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.*;
import com.miplus.ccrm.core.controller.vo.action.*;
import com.miplus.ccrm.core.controller.vo.conf.WfNextStepVo;
import com.miplus.ccrm.core.controller.vo.action.StopCaseListVo;
import com.miplus.ccrm.core.controller.vo.credit.CrdCaseReqVo;
import com.miplus.ccrm.core.controller.vo.credit.CrdCaseResVo;
import com.miplus.ccrm.core.controller.vo.credit.SysTagsColor;
import com.miplus.ccrm.core.controller.vo.cust.CustResVo;
import com.miplus.ccrm.core.controller.vo.cust.StopCustomerListReqVo;
import com.miplus.ccrm.core.mapper.*;
import com.miplus.ccrm.core.pojo.*;
import com.miplus.ccrm.core.service.ExportService;
import com.miplus.ccrm.core.service.FiWorkFlowCase;
import com.miplus.ccrm.core.service.crd.FiImportHistService;
import com.miplus.ccrm.core.service.crd.FiTaskService;
import com.miplus.ccrm.core.service.cust.ConCustomertagService;
import com.miplus.ccrm.core.service.strategy.CpCalllistService;
import com.miplus.ccrm.core.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
* @author pc
* @description 针对表【fi_stopcall(号码停催表)】的数据库操作Service实现
* @createDate 2024-04-02 19:24:07
*/
@Slf4j
@Service
public class FiStopcallServiceImpl extends MPJBaseServiceImpl<FiStopcallMapper, FiStopcall>
    implements FiStopcallService{
    @Resource
    private FiTaskService fiTaskService;
    @Resource
    private CpCalllistService cpCalllistService;
    @Resource
    private FiWorkFlowCase fiWorkFlowCase;
    @Resource
    private ConContactMapper conContactMapper;
    @Resource
    private FiCreditcasesMapper fiCreditcasesMapper;

    @Resource
    private ConCustomerMapper conCustomerMapper;

    @Resource
    private ConCustomertagService conCustomertagService;

    @Resource
    private ExportService exportService;
    @Resource
    private FiImportHistService fiImportHistService;
    @Resource
    FiCreditcasesHistMapper fiCreditcasesHistMapper;

    @Override
    public IPage<FiStopResVo> fiStopCallList(JSysUser user, FiStopReqVo paras)
    {
        String $usrid=user.getUsrid();
//        Boolean phnDisStar= JUsrPerm.hasPermission(user,JUsrPerm.DISSTAR_PHN);
        String stoptype=paras.getStoptype();
        if(JPubUtils.IsNotEmpty(stoptype)){
            stoptype=stoptype.toUpperCase();
        }
        IPage<FiStopResVo> resVoIPage=selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                FiStopResVo.class,
                new MPJLambdaWrapper<FiStopcall>()
                        .selectAs("fun_getnames('FI.STOPCALL.STATUS',t.status)", FiStopResVo::getStatusdsc)
                        .selectAs("fun_getnames('FI.STOPCALL.TYPE',t.stoptype)", FiStopResVo::getStoptypedsc)
                        .selectAs("fun_getnames('FI.STOPCALL.REASON',t.reason)", FiStopResVo::getReasondsc)
                        .selectAs("(select cl.wfid from cp_calllist cl where cl.clid=t.clid)", FiStopResVo::getWfid)
                        .selectAs("fun_getgrpname(t.applyusr)",FiStopResVo::getApplygrp)
                        .selectAll(FiStopcall.class)
                        .apply("fc_hasApplyView(t.stopid,'SYS_STOPCALL',t.applyusr,{0},t.status,t.confirmusr)>0",$usrid)
                        .apply(JPubUtils.IsNotEmpty(paras.getApplygrp()),"fc_hasUsrInGroup(t.applyusr,{0})>0",paras.getApplygrp())
                        .eq(JPubUtils.IsNotEmpty(paras.getStopkey()),FiStopcall::getStopkey,paras.getStopkey())
                        .eq(JPubUtils.IsNotEmpty(stoptype),FiStopcall::getStoptype,stoptype)
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),FiStopcall::getStatus,paras.getStatus())
                        .eq(JPubUtils.IsNotEmpty(paras.getApplyusr()),FiStopcall::getApplyusr,paras.getApplyusr())
//                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .ge(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt, paras.getStartdt())
                        .le(JPubUtils.IsNotEmpty(paras.getEnddt()), FiStopcall::getApplydt, paras.getEnddt())
        );
//        resVoIPage.convert(u->{
//            if(!phnDisStar&&(!JPubUtils.IsEqual(u.getStoptype(),"CASE"))){
//                u.setStopkey(JPubUtils.getStarString(JPubUtils.STAR_PHN,u.getStopkey()));
//            }
//            return u;
//        });

        return resVoIPage;
    }

    @Override
    public CmdResVo expFiStopCall(JSysUser user, FiStopReqVo paras, HttpServletResponse response) {
        String $usrid=user.getUsrid();

        IPage<FiStopResVo> pages=fiStopCallList(user, paras);
        ArrayList arr=new ArrayList();

        String exptempid=JPubUtils.getExpTempID(paras.getExpfilename(),"停催列表");
        String filename=JPubUtils.getExpFileName(
                paras.getExpfilename(),exptempid
        );
        pages.convert(u->{
            HashMap map=JPubUtils.toExportMap(u);
            if(map!=null) arr.add(map);
            return u;
        });
        CmdResVo resVo=exportService.ToExcel(
                response,
                arr,
                paras.getExpidlist(),
                paras.getExpnamelist(),
                filename,
                $usrid
        );

        int okcount=resVo.getCount();
        if(okcount>0){
            fiImportHistService.AddExportHist(
                    resVo.getKeyId(),
                    $usrid,
                    exptempid,
                    filename,
                    okcount
            );
        }

        return resVo;
    }

    @Override
    public IPage<FiStopCaseResVo> fiStopCaseList(JSysUser user, FiStopReqVo paras) {

        String $usrid=user.getUsrid();
        Boolean phnDisStar= JUsrPerm.hasPermission(user,JUsrPerm.DISSTAR_PHN);
        String idstar= JUsrPerm.getPermission(user,JUsrPerm.DISSTAR_IDNO);
        String stoptype=paras.getStoptype();
        if(JPubUtils.IsNotEmpty(stoptype)){
            stoptype=stoptype.toUpperCase();
        }
        IPage<FiStopCaseResVo> resVoIPage=selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                FiStopCaseResVo.class,
                new MPJLambdaWrapper<FiStopcall>()
                        .leftJoin(FiCreditcases.class,"fi",FiCreditcases::getCreditcaseid,FiStopcall::getStopkey)
                        .leftJoin(ConCustomer.class,"c",ConCustomer::getCustomernumber,FiCreditcases::getCustomernumber)
                        .leftJoin("iou_product ioup on ioup.product_id = fi.product_id and ifnull(ioup.merchant_id,'') = ifnull(fi.merchant_id,'')")
//                        .leftJoin(IouProduct.class, "ioup",
//                                on->(on.eq(IouProduct::getProductId, FiCreditcases::getProductId)
//                                        .eq(IouProduct::getMerchantId,FiCreditcases::getMerchantId)
////                                        .eq(IouProduct::getProductType,FiCreditcases::getProdtype)
//                                ))
                        .selectAs("fun_getnames('FI.STOPCALL.STATUS',t.status)", FiStopResVo::getStatusdsc)
                        .selectAs("fun_getnames('FI.STOPCALL.TYPE',t.stoptype)", FiStopResVo::getStoptypedsc)
                        .selectAs("fun_getnames('FI.STOPCALL.REASON',t.reason)", FiStopResVo::getReasondsc)
                        .selectAs("(select cl.wfid from cp_calllist cl where cl.clid=t.clid)", FiStopResVo::getWfid)
                        .selectAs("fun_getgrpname(t.applyusr)",FiStopResVo::getApplygrp)
                        .selectAs(FiCreditcases::getProductName,FiStopCaseResVo::getProductName)
                        .selectAs(FiCreditcases::getMthsDay,FiStopCaseResVo::getMthsDay)
                        .selectAs(ConCustomer::getCustname,FiStopCaseResVo::getCustname)
                        .selectAs(ConCustomer::getCustomernumber,FiStopCaseResVo::getCustomernumber)
//                        .selectAs(ConCustomer::getOpenacctcertno,FiStopCaseResVo::getOpenacctcertno)
                        .selectAs(String.format("fi_starSecu('%s','%s',c.openacctcertno,'%s')",$usrid,JUsrPerm.DISSTAR_IDNO,idstar),FiStopCaseResVo::getOpenacctcertno)
                        .selectAll(FiStopcall.class)
                        .selectAs("ioup.merchant_name", CrdCaseResVo::getMerchantname)//商户
                        .selectAs("case when t.stopcasemode = 1 then '案件提醒' when t.stopcasemode = 2 then '案件逾期' else '全部' end ",FiStopCaseResVo::getStopcasemodedsc)
                        .apply("fc_hasApplyView(t.stopid,'SYS_STOPCALL',t.applyusr,{0},t.status,t.confirmusr)>0",$usrid)
                        .apply(JPubUtils.IsNotEmpty(paras.getApplygrp()),"fc_hasUsrInGroup(t.applyusr,{0})>0",paras.getApplygrp())
                        .eq(JPubUtils.IsNotEmpty(paras.getStopkey()),FiStopcall::getStopkey,paras.getStopkey())
                        .eq(JPubUtils.IsNotEmpty(stoptype),FiStopcall::getStoptype,stoptype)
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),FiStopcall::getStatus,paras.getStatus())
                        .eq(JPubUtils.IsNotEmpty(paras.getCustomernumber()),ConCustomer::getCustomernumber,paras.getCustomernumber())
                        .in(JPubUtils.IsNotEmpty(paras.getProductIdList()),"ioup.id",paras.getProductIdList())
                        .like(JPubUtils.IsNotEmpty(paras.getCustname()),ConCustomer::getCustname,paras.getCustname())
                        .eq(JPubUtils.IsNotEmpty(paras.getApplyusr()),FiStopcall::getApplyusr,paras.getApplyusr())
//                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .ge(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt, paras.getStartdt())
                        .le(JPubUtils.IsNotEmpty(paras.getEnddt()), FiStopcall::getApplydt, paras.getEnddt())
                        .eq(JPubUtils.IsNotEmpty(paras.getStopcasemode()),FiStopcall::getStopcasemode,paras.getStopcasemode())
        );
        resVoIPage.convert(u->{
            if(!phnDisStar&&(!JPubUtils.IsEqual(u.getStoptype(),"CASE"))){
                u.setStopkey(JPubUtils.getStarString(JPubUtils.STAR_PHN,u.getStopkey()));
            }
            return u;
        });

        return resVoIPage;
    }
    private IPage<FiStopCaseResVo> fiStopCaseListExpFiStop(JSysUser user, FiStopReqVo paras) {

        String $usrid=user.getUsrid();
        Boolean phnDisStar= JUsrPerm.hasPermission(user,JUsrPerm.DISSTAR_PHN);
//        String idstar= JUsrPerm.getPermission(user,JUsrPerm.DISSTAR_IDNO);
        String stoptype=paras.getStoptype();
        if(JPubUtils.IsNotEmpty(stoptype)){
            stoptype=stoptype.toUpperCase();
        }
        IPage<FiStopCaseResVo> resVoIPage=selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                FiStopCaseResVo.class,
                new MPJLambdaWrapper<FiStopcall>()
                        .leftJoin(FiCreditcases.class,"fi",FiCreditcases::getCreditcaseid,FiStopcall::getStopkey)
                        .leftJoin(ConCustomer.class,"c",ConCustomer::getCustomernumber,FiCreditcases::getCustomernumber)
                        .leftJoin("iou_product ioup on ioup.product_id = fi.product_id and ifnull(ioup.merchant_id,'') = ifnull(fi.merchant_id,'')")
//
//                        .leftJoin(IouProduct.class, "ioup",
//                                on->(on.eq(IouProduct::getProductId, FiCreditcases::getProductId)
//                                        .eq(IouProduct::getMerchantId,FiCreditcases::getMerchantId)
////                                        .eq(IouProduct::getProductType,FiCreditcases::getProdtype)
//                                ))
                        .selectAs("fun_getnames('FI.STOPCALL.STATUS',t.status)", FiStopResVo::getStatusdsc)
                        .selectAs("fun_getnames('FI.STOPCALL.TYPE',t.stoptype)", FiStopResVo::getStoptypedsc)
                        .selectAs("fun_getnames('FI.STOPCALL.REASON',t.reason)", FiStopResVo::getReasondsc)
                        .selectAs("(select cl.wfid from cp_calllist cl where cl.clid=t.clid)", FiStopResVo::getWfid)
                        .selectAs("fun_getgrpname(t.applyusr)",FiStopResVo::getApplygrp)
                        .selectAs(FiCreditcases::getProductName,FiStopCaseResVo::getProductName)
                        .selectAs(FiCreditcases::getMthsDay,FiStopCaseResVo::getMthsDay)
                        .selectAs(ConCustomer::getCustname,FiStopCaseResVo::getCustname)
                        .selectAs(ConCustomer::getCustomernumber,FiStopCaseResVo::getCustomernumber)
//                        .selectAs(ConCustomer::getOpenacctcertno,FiStopCaseResVo::getOpenacctcertno)
                        .selectAs(String.format("fi_starSecu('%s','%s',c.openacctcertno,'%s')",null,JUsrPerm.DISSTAR_IDNO,""),FiStopCaseResVo::getOpenacctcertno)
                        .selectAll(FiStopcall.class)
                        .selectAs("ioup.merchant_name", CrdCaseResVo::getMerchantname)//商户
                        .apply("fc_hasApplyView(t.stopid,'SYS_STOPCALL',t.applyusr,{0},t.status,t.confirmusr)>0",$usrid)
                        .apply(JPubUtils.IsNotEmpty(paras.getApplygrp()),"fc_hasUsrInGroup(t.applyusr,{0})>0",paras.getApplygrp())
                        .eq(JPubUtils.IsNotEmpty(paras.getStopkey()),FiStopcall::getStopkey,paras.getStopkey())
                        .eq(JPubUtils.IsNotEmpty(stoptype),FiStopcall::getStoptype,stoptype)
                        .eq(JPubUtils.IsNotEmpty(paras.getCustomernumber()),ConCustomer::getCustomernumber,paras.getCustomernumber())
                        .in(JPubUtils.IsNotEmpty(paras.getProductIdList()),"ioup.id",paras.getProductIdList())
                        .like(JPubUtils.IsNotEmpty(paras.getCustname()),ConCustomer::getCustname,paras.getCustname())
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),FiStopcall::getStatus,paras.getStatus())
                        .eq(JPubUtils.IsNotEmpty(paras.getApplyusr()),FiStopcall::getApplyusr,paras.getApplyusr())
//                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .ge(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt, paras.getStartdt())
                        .le(JPubUtils.IsNotEmpty(paras.getEnddt()), FiStopcall::getApplydt, paras.getEnddt())
        );
        resVoIPage.convert(u->{
            if(!phnDisStar&&(!JPubUtils.IsEqual(u.getStoptype(),"CASE"))){
                u.setStopkey(JPubUtils.getStarString(JPubUtils.STAR_PHN,u.getStopkey()));
            }
            return u;
        });

        return resVoIPage;
    }
    @Override
    public CmdResVo expFiStopCase(JSysUser user, FiStopReqVo paras, HttpServletResponse response) {
        String $usrid=user.getUsrid();

        IPage<FiStopCaseResVo> pages=fiStopCaseListExpFiStop(user, paras);
        ArrayList arr=new ArrayList();

        String exptempid=JPubUtils.getExpTempID(paras.getExpfilename(),"停催列表");
        String filename=JPubUtils.getExpFileName(
                paras.getExpfilename(),exptempid
        );
        pages.convert(u->{
            HashMap map=JPubUtils.toExportMap(u);
            if(map!=null) arr.add(map);
            return u;
        });
        CmdResVo resVo=exportService.ToExcel(
                response,
                arr,
                paras.getExpidlist(),
                paras.getExpnamelist(),
                filename,
                $usrid
        );

        int okcount=resVo.getCount();
        if(okcount>0){
            fiImportHistService.AddExportHist(
                    resVo.getKeyId(),
                    $usrid,
                    exptempid,
                    filename,
                    okcount
            );
        }

        return resVo;
    }



    @Override
    public IPage<FiStopCustomerResVo> fiStopCustomerList(JSysUser user, FiStopCustomerReqVo paras) {
        String $usrid=user.getUsrid();
//        Boolean phnDisStar= JUsrPerm.hasPermission(user,JUsrPerm.DISSTAR_PHN);
        String idstar= JUsrPerm.getPermission(user,JUsrPerm.DISSTAR_IDNO);
        String tags=JPubUtils.getInString(paras.getTags());
        String stoptype="CUSTOMER";

        return selectJoinListPage(new Page<>(paras.getPageNum(),paras.getPageSize()),
                FiStopCustomerResVo.class,
                new MPJLambdaWrapper<>(FiStopcall.class)
                        .leftJoin(ConCustomer.class,"c",ConCustomer::getCustomernumber,FiStopcall::getStopkey)
                        .selectAs("fun_getnames('FI.STOPCALL.STATUS',t.status)", FiStopCustomerResVo::getStatusdsc)
                        .selectAs("(select cl.wfid from cp_calllist cl where cl.clid=t.clid)", FiStopCustomerResVo::getWfid)
                        .selectAs("fun_getnames('CUST.TYPE',c.type)", FiStopCustomerResVo::getTypedsc)
                        .selectAs("fun_getnames('CON.CERTTYPE',c.openacctcerttype)",FiStopCustomerResVo::getOpenacctcerttype)
                        .selectAs(String.format("fi_starSecu('%s','%s',c.openacctcertno,'%s')",$usrid,JUsrPerm.DISSTAR_IDNO,idstar),FiStopCustomerResVo::getOpenacctcertno)
                        .selectAs(String.format("fi_starSecu('%s','disstar.phone',c.mobile,'')",$usrid), CustResVo::getMobile)
                        .selectAll(FiStopcall.class)
                        .select(ConCustomer::getCustomernumber,ConCustomer::getType,ConCustomer::getCustname,
                                ConCustomer::getPrododudtotalPrin,ConCustomer::getProdmthsStage,ConCustomer::getOverdueDays)
                        .apply("fc_hasApplyView(t.stopid,'SYS_STOPCALL',t.applyusr,{0},t.status,t.confirmusr)>0",$usrid)
                        .eq(JPubUtils.IsNotEmpty(stoptype),FiStopcall::getStoptype,stoptype)
                        .eq(JPubUtils.IsNotEmpty(paras.getCustomernumber()),ConCustomer::getCustomernumber,paras.getCustomernumber())
                        .like(JPubUtils.IsNotEmpty(paras.getIdnumber()),ConCustomer::getOpenacctcertno,paras.getIdnumber())
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),FiStopcall::getStatus,paras.getStatus())
                        .eq(JPubUtils.IsNotEmpty(paras.getType()),ConCustomer::getType,paras.getType())
                        .likeRight(JPubUtils.IsNotEmpty(paras.getCustname()),ConCustomer::getCustname,paras.getCustname())
                        .exists(JPubUtils.IsNotEmpty(tags),String.format("select 1 from con_customertag tag where tag.custid=c.customernumber and tag.id in ('%s')",tags))
//                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .ge(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt, paras.getStartdt())
                        .le(JPubUtils.IsNotEmpty(paras.getEnddt()), FiStopcall::getApplydt, paras.getEnddt())
        ).convert(x->{
            List<SysTagsColor> custtags=conCustomertagService.selectJoinList(SysTagsColor.class,
                    new MPJLambdaWrapper<>(ConCustomertag.class)
                            .leftJoin(SysTags.class,SysTags::getId,ConCustomertag::getId)
                            .selectAs(ConCustomertag::getId,SysTagsColor::getId)
                            .selectAs(SysTags::getName,SysTagsColor::getDsc)
                            .selectAs(SysTags::getColor,SysTagsColor::getColor)
                            .eq(ConCustomertag::getCustid,x.getCustomernumber())
            );
            x.setTags(custtags);
            return x;
        });

    }

    private IPage<FiStopCustomerResVo> fiStopCustomerListExpFiStop(JSysUser user, FiStopCustomerReqVo paras) {
        String $usrid=user.getUsrid();
//        Boolean phnDisStar= JUsrPerm.hasPermission(user,JUsrPerm.DISSTAR_PHN);
//        String idstar= JUsrPerm.getPermission(user,JUsrPerm.DISSTAR_IDNO);
        String tags=JPubUtils.getInString(paras.getTags());
        String stoptype="CUSTOMER";

        return selectJoinListPage(new Page<>(paras.getPageNum(),paras.getPageSize()),
                FiStopCustomerResVo.class,
                new MPJLambdaWrapper<>(FiStopcall.class)
                        .leftJoin(ConCustomer.class,"c",ConCustomer::getCustomernumber,FiStopcall::getStopkey)
                        .selectAs("fun_getnames('FI.STOPCALL.STATUS',t.status)", FiStopCustomerResVo::getStatusdsc)
                        .selectAs("(select cl.wfid from cp_calllist cl where cl.clid=t.clid)", FiStopCustomerResVo::getWfid)
                        .selectAs("fun_getnames('CUST.TYPE',c.type)", FiStopCustomerResVo::getTypedsc)
                        .selectAs("fun_getnames('CON.CERTTYPE',c.openacctcerttype)",FiStopCustomerResVo::getOpenacctcerttype)
                        .selectAs(String.format("fi_starSecu('%s','%s',c.openacctcertno,'%s')",null,JUsrPerm.DISSTAR_IDNO,null),FiStopCustomerResVo::getOpenacctcertno)
                        .selectAs(String.format("fi_starSecu('%s','disstar.phone',c.mobile,'')",$usrid), CustResVo::getMobile)
                        .selectAll(FiStopcall.class)
                        .select(ConCustomer::getCustomernumber,ConCustomer::getType,ConCustomer::getCustname,
                                ConCustomer::getPrododudtotalPrin,ConCustomer::getProdmthsStage,ConCustomer::getOverdueDays)
                        .apply("fc_hasApplyView(t.stopid,'SYS_STOPCALL',t.applyusr,{0},t.status,t.confirmusr)>0",$usrid)
                        .eq(JPubUtils.IsNotEmpty(stoptype),FiStopcall::getStoptype,stoptype)
                        .eq(JPubUtils.IsNotEmpty(paras.getCustomernumber()),ConCustomer::getCustomernumber,paras.getCustomernumber())
                        .like(JPubUtils.IsNotEmpty(paras.getIdnumber()),ConCustomer::getOpenacctcertno,paras.getIdnumber())
                        .eq(JPubUtils.IsNotEmpty(paras.getStatus()),FiStopcall::getStatus,paras.getStatus())
                        .eq(JPubUtils.IsNotEmpty(paras.getType()),ConCustomer::getType,paras.getType())
                        .likeRight(JPubUtils.IsNotEmpty(paras.getCustname()),ConCustomer::getCustname,paras.getCustname())
                        .exists(JPubUtils.IsNotEmpty(tags),String.format("select 1 from con_customertag tag where tag.custid=c.customernumber and tag.id in ('%s')",tags))
//                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .ge(JPubUtils.IsNotEmpty(paras.getStartdt()), FiStopcall::getApplydt, paras.getStartdt())
                        .le(JPubUtils.IsNotEmpty(paras.getEnddt()), FiStopcall::getApplydt, paras.getEnddt())
        ).convert(x->{
            List<SysTagsColor> custtags=conCustomertagService.selectJoinList(SysTagsColor.class,
                    new MPJLambdaWrapper<>(ConCustomertag.class)
                            .leftJoin(SysTags.class,SysTags::getId,ConCustomertag::getId)
                            .selectAs(ConCustomertag::getId,SysTagsColor::getId)
                            .selectAs(SysTags::getName,SysTagsColor::getDsc)
                            .selectAs(SysTags::getColor,SysTagsColor::getColor)
                            .eq(ConCustomertag::getCustid,x.getCustomernumber())
            );
            x.setTags(custtags);
            return x;
        });

    }

    @Override
    public CmdResVo expFiStopCustomer(JSysUser user, FiStopCustomerReqVo paras, HttpServletResponse response) {

        String $usrid=user.getUsrid();
        IPage<FiStopCustomerResVo> pages=fiStopCustomerListExpFiStop(user, paras);
        ArrayList arr=new ArrayList();

        String exptempid=JPubUtils.getExpTempID(paras.getExpfilename(),"停催列表");
        String filename=JPubUtils.getExpFileName(
                paras.getExpfilename(),exptempid
        );
        pages.convert(u->{
            HashMap map=JPubUtils.toExportMap(u);
            if(map!=null) arr.add(map);
            return u;
        });
        CmdResVo resVo=exportService.ToExcel(
                response,
                arr,
                paras.getExpidlist(),
                paras.getExpnamelist(),
                filename,
                $usrid
        );

        int okcount=resVo.getCount();
        if(okcount>0){
            fiImportHistService.AddExportHist(
                    resVo.getKeyId(),
                    $usrid,
                    exptempid,
                    filename,
                    okcount
            );
        }

        return resVo;
    }

    @Override
    @Transactional
    public CmdResVo fiStopCallAdd(String $usrid, FiStopAddVo paras)
    {
        if(JPubUtils.IsEmpty(paras.getPhone())&&JPubUtils.IsEmpty(paras.getFicaseid())){
            throw new ServiceException(EnumRCode.ArgErr.value, EnumRCode.ArgErr.name);
        }
        String stopkey=paras.getPhone();
        if(JPubUtils.IsEqual(paras.getStoptype(),"CASE")){
            stopkey=paras.getFicaseid().toString();
        }
        else if(JPubUtils.IsNotEmpty(paras.getContactnumber())){
            ConContact contact=conContactMapper.selectById(paras.getContactnumber());
            stopkey=contact.getPhone();
        }
        FiStopcall fiStopcall=selectJoinOne(FiStopcall.class,
                new MPJLambdaWrapper<FiStopcall>()
                        .eq(FiStopcall::getStopkey,stopkey)
                        .eq(FiStopcall::getStoptype,paras.getStoptype())
                        .eq(ObjectUtils.isNotNull(paras.getStopcasemode()),FiStopcall::getStopcasemode,paras.getStopcasemode())
                        .in(FiStopcall::getStatus,EnumConfirmStatus.New.value,
                                EnumConfirmStatus.Pending.value,
                                EnumConfirmStatus.Pass.value)
        );
        //相同的案件或号码正在审核中
        if(fiStopcall!=null) {
            if (fiStopcall.getStatus() == EnumConfirmStatus.Pending.value) {
                throw new ServiceException(EnumRCode.DataPending.value, EnumRCode.DataPending.name);
            }
            else if(fiStopcall.getStatus() == EnumConfirmStatus.New.value ||
                    fiStopcall.getStatus() == EnumConfirmStatus.Pass.value){
                throw new ServiceException(EnumRCode.DataProcess.value, EnumRCode.DataProcess.name);
            }
        }
        String clid=paras.getClid();
        if(JPubUtils.IsEmpty(clid)){
            clid="SYS_STOPCALL"; //此任务是系统配置任务，不能delete
        }

        Integer wfid=cpCalllistService.getCalllistWfID(clid);

        int tasknumber=0;
        //CAMPAIGN.CHANNEL=10停催
        if(JPubUtils.IsNotEmpty(paras.getFicaseid())) { //从客户信息处添加，没有案件时，不关联催记
            tasknumber = fiTaskService.addTask($usrid, clid, paras.getFicaseid(),
                    EnumFiChannel.StopCall.value,
                    paras.getContactnumber(), stopkey,null,paras.getStoptype()+"停催："+paras.getApplydsc()
            );
        }

        int ret=0;
        log.info("applyAdd:clid={},stopkey={},tasknumber={},wfid={}",clid,stopkey,tasknumber,wfid);

        int stopid=0;
        FiStopcall fi = new FiStopcall();
        fi.setStopkey(stopkey);
        fi.setStoptype(paras.getStoptype());
        fi.setClid(clid);
        fi.setStopdays(paras.getStopdays());
        fi.setReason(paras.getReason());
        fi.setFicaseid(paras.getFicaseid());
        fi.setApplydsc(paras.getApplydsc());
        fi.setStopenddt(JPubUtils.addDays(new Date(), paras.getStopdays()));
        fi.setTasknumber(tasknumber);
        fi.setApplyusr($usrid);
        fi.setApplydt(new Date());
        fi.setStatus(EnumConfirmStatus.New.value); //新建
        fi.setStopcasemode(paras.getStopcasemode());
        if(fiStopcall!=null) {
            stopid=fiStopcall.getStopid();
            //这里要主要update后，stopid不会反写到实体类里面
            ret=baseMapper.update(fi,new UpdateWrapper<FiStopcall>()
                    .lambda()
                    .eq(FiStopcall::getStopid,stopid)
                    .set(FiStopcall::getConfirmdsc,null)
                    .set(FiStopcall::getConfirmdt,null)
                    .set(FiStopcall::getConfirmusr,null)
                    .set(FiStopcall::getClosedsc,null)
                    .set(FiStopcall::getClosedt,null)
                    .set(FiStopcall::getCloseusr,null)
            );
        }
        else{
            fi.setCrdt(new Date());
            fi.setCrusr($usrid);
            ret=baseMapper.insert(fi);

            stopid=fi.getStopid();
        }

        if(wfid>0){
            //wfid=0 表示此任务clid没有配置工作流，前台可以根据是否有wfid显示不通的审批流程或状态
            String status=fiWorkFlowCase.doCreate($usrid,wfid,stopid,tasknumber);
            fi = new FiStopcall();
            fi.setStopid(stopid);
            fi.setStatus(Integer.parseInt(status)); //处理中
            baseMapper.updateById(fi);
        }

        return new CmdResVo(ret,Integer.toString(fi.getStopid()));
    }

    @Override
    public CmdResVo fiStopCallCancel(String $usrid, FiApplyCancelVo paras)
    {
        FiStopcall fi=baseMapper.selectById(paras.getApplynumber());
        if(JPubUtils.IsNotEmpty(fi.getTasknumber())){
            fiTaskService.updateStatus(fi.getTasknumber(),$usrid,"X");
        }
        else{
            log.warn("applyCancel.getTasknumber.isnull");
        }
        Integer wfid=cpCalllistService.getCalllistWfID(fi.getClid());
        if(wfid>0){//有工作流,取消
            fiWorkFlowCase.doCancel($usrid,wfid,fi.getStopid());
        }

        fi = new FiStopcall();
        fi.setStopid(paras.getApplynumber());
        fi.setStatus(EnumConfirmStatus.Cancel.value); //取消
        fi.setCloseusr($usrid);
        fi.setClosedt(new Date());
        fi.setClosedsc(EnumConfirmStatus.Cancel.name);
        int ret=baseMapper.updateById(fi);

        return new CmdResVo(ret,fi.getStopid().toString());
    }

    @Override
    public CmdResVo fiStopCallEnd(String $usrid, FiApplyCancelVo paras)
    {
        FiStopcall fi = baseMapper.selectById(paras.getApplynumber());
        fi.setStatus(EnumConfirmStatus.Stop.value); //终止
        fi.setCloseusr($usrid);
        fi.setClosedt(new Date());
        fi.setClosedsc(EnumConfirmStatus.Stop.name);
        int ret=baseMapper.updateById(fi);

        if(JPubUtils.IsNotEmpty(fi.getFicaseid())&&
                JPubUtils.IsEqual(fi.getStoptype(),"CASE")) {
            SetFiCaseStopCallEnd($usrid, fi.getFicaseid());
        }

        if(JPubUtils.IsNotEmpty(fi.getStopkey())&&
                JPubUtils.IsEqual(fi.getStoptype(),"CUSTOMER")) {
            SetFiCustomerStopCallEnd($usrid, fi.getStopkey());
        }

        return new CmdResVo(ret,fi.getStopid().toString());
    }

    @Override
    public CmdResVo fiStopCallConfirm(String $usrid, FiApplyConfirmVo paras)
    {
        boolean confirmend=true;
        String okstatus=paras.getActionid().toString();
        FiStopcall fi=baseMapper.selectById(paras.getApplynumber());
        if(JPubUtils.IsNotEmpty(paras.getCaseactid())){
            //需要走工作流
            WfNextStepVo wfNextStepVo=fiWorkFlowCase.doExec($usrid,paras.getCaseactid(),
                    paras.getActionid(),paras.getWfcaseid(),paras.getConfirmdsc()
            );
            okstatus=wfNextStepVo.getStatus();

            //可能有多级审核,3=审核全部完成
            if(!JPubUtils.IsEqual(wfNextStepVo.getType(), EnumWorkFlowStep.End.value)) {
                confirmend=false;
            }
        }
        else{
            Integer wfid=cpCalllistService.getCalllistWfID(fi.getClid());
            if(wfid==null||wfid==0){//不使用工作流,这种情况下okstatus就是字典ID，直接写审核结果
                log.info("fiStopCallConfirm.nouse workflow：okstatus={}",okstatus);
            }
            else{//可能配置错误或网络引起的，2024-08-29
                log.warn("fiStopCallConfirm.nofind wf caseactid.");
                throw new ServiceException(EnumRCode.WfDataErr.value, EnumRCode.WfDataErr.name);
            }
        }

        //单纯就是审批流程，结果后续操作就在这里写，如果有后续反馈的，在result里面写，比如外访
        if(JPubUtils.IsNotEmpty(fi.getTasknumber())&&confirmend) {
            fiTaskService.updateStatus(
                    fi.getTasknumber(),
                    $usrid,
                    fiWorkFlowCase.getPassStatus(okstatus)
            );
            if(JPubUtils.IsEqual(okstatus,EnumConfirmStatus.Pass.value)&&
                    JPubUtils.IsEqual(fi.getStoptype(),"CASE")) {//审核通过
                SetFiCaseStopCall($usrid,fi.getFicaseid());
            }
            else if(JPubUtils.IsEqual(okstatus,EnumConfirmStatus.Pass.value)&&
                    JPubUtils.IsEqual(fi.getStoptype(),"CUSTOMER")) {//审核通过 客户停催
                SetFiCustomerStopCall($usrid,fi.getStopkey());
            }
        }

        int ret=0;
        if(JPubUtils.IsNotEmpty(okstatus)){
            fi = new FiStopcall();
            fi.setStopid(paras.getApplynumber());
            fi.setStatus(Integer.parseInt(okstatus));
            fi.setConfirmusr($usrid);
            fi.setConfirmdt(new Date());
            fi.setConfirmdsc(paras.getConfirmdsc());
            ret=baseMapper.updateById(fi);
        }

        return new CmdResVo(ret,paras.getApplynumber().toString());
    }

    @Override
    public CmdResVo fiStopCallEndList(String $usrid, List<String> paras)
    {
        for(String id : paras) {
            FiStopcall fi =baseMapper.selectById(Integer.parseInt(id));
            fi.setStatus(EnumConfirmStatus.Stop.value); //终止
            fi.setCloseusr($usrid);
            fi.setClosedt(new Date());
            fi.setClosedsc(EnumConfirmStatus.Stop.name);
            baseMapper.updateById(fi);
            if(JPubUtils.IsNotEmpty(fi.getFicaseid())&&
                    JPubUtils.IsEqual(fi.getStoptype(),"CASE")) {
                SetFiCaseStopCallEnd($usrid, fi.getFicaseid());
            }
        }
        return new CmdResVo(paras.size());
    }

    private int updateStopCall(String $usrid,String stopkey,String stoptype,Integer stopcasemode, Integer stopdays,String reason,String applydsc)
    {
        int ret=0;
        boolean isupdate=true;
        if(JPubUtils.IsEmpty(stopkey)){
            log.warn("updateStopCall:keyval isnull");
            return 0;
        }
        //2024-06-26 edit in
        FiStopcall fiStopcall=selectJoinOne(FiStopcall.class,
                new MPJLambdaWrapper<FiStopcall>()
                        .eq(FiStopcall::getStopkey,stopkey)
                        .eq(FiStopcall::getStoptype,stoptype)
                        .eq(ObjectUtils.isNotNull(stopcasemode),FiStopcall::getStopcasemode,stopcasemode)
                        .in(FiStopcall::getStatus,EnumConfirmStatus.New.value,
                                EnumConfirmStatus.Pending.value,
                                EnumConfirmStatus.Pass.value)
                        .last("limit 1")
        );
        if(fiStopcall==null){
            isupdate=false;
        }
        fiStopcall=new FiStopcall();
        fiStopcall.setStatus(EnumConfirmStatus.Pass.value);
        fiStopcall.setApplydt(new Date());
        fiStopcall.setApplyusr($usrid);
        fiStopcall.setReason(reason);
        fiStopcall.setStoptype(stoptype);
        fiStopcall.setStopcasemode(stopcasemode);
        fiStopcall.setStopdays(stopdays);
        fiStopcall.setStopenddt(JPubUtils.addDays(new Date(), stopdays));
        fiStopcall.setApplydsc(applydsc);
        fiStopcall.setConfirmdt(new Date());
        fiStopcall.setConfirmusr($usrid);
        fiStopcall.setConfirmdsc("批量停催");
        if(JPubUtils.IsEqual(stoptype,EnumFiCaseStopType.CASE.value)||
                JPubUtils.IsEqual(stoptype,EnumFiCaseStopType.AI.value)){//2024-07-09
            fiStopcall.setFicaseid(JPubUtils.StrDateToInt(stopkey));
        }
        if(!isupdate){
            fiStopcall.setStopkey(stopkey);
            fiStopcall.setCrdt(new Date());
            fiStopcall.setCrusr($usrid);
            ret=baseMapper.insert(fiStopcall);
        }
        else{
            ret=baseMapper.update(fiStopcall,new UpdateWrapper<FiStopcall>()
                        .lambda()
                        .eq(FiStopcall::getStopid,fiStopcall.getStopid())
                        .set(FiStopcall::getClosedsc,null)
                        .set(FiStopcall::getClosedt,null)
                        .set(FiStopcall::getCloseusr,null)
                );
        }

        return ret;
    }

    @Override
    public CmdResVo fiStopCallListAdd(String $usrid, StopCallListVo paras)
    {
        int ret=0;
        for(String phone : paras.getPhonelist()) {
            if(paras.getIsstopcall()==1) {
                updateStopCall($usrid, phone.trim(),"CALL",null,
                        paras.getStopdays(),paras.getReason(),paras.getApplydsc());
            }
            if(paras.getIsstopsms()==1){
                updateStopCall($usrid, phone.trim(),"SMS",null,
                        paras.getStopdays(),paras.getReason(),paras.getApplydsc());
            }
            ret++;
        }
        return new CmdResVo(ret);
    }

    @Override
    public CmdResVo fiStopCaseListAdd(String $usrid, StopCaseListVo paras)
    {
        int ret=0;
        //List<String>
        for(Integer ficaseid : paras.getCaselist()) {
            if(JPubUtils.IsEmpty(ficaseid)) continue;

            //int caseid=Integer.parseInt(ficaseid);
            if(JPubUtils.IsEqual(paras.getStoptype(), EnumFiCaseStopType.CASE.value)) {
                Integer tasknumber = fiTaskService.addTask($usrid, "SYS_STOPCALL", ficaseid,
                        EnumFiChannel.StopCall.value, null, null, null, "CASE批量停催：" + paras.getApplydsc()
                );

                updateStopCall($usrid, String.valueOf(ficaseid), "CASE",null,
                        paras.getStopdays(), paras.getReason(), paras.getApplydsc());

                SetFiCaseStopCall($usrid, ficaseid);

                fiTaskService.updateStatus(
                        tasknumber,
                        $usrid,
                        fiWorkFlowCase.getPassStatus(String.format("%d", EnumConfirmStatus.Pass.value))
                );
            }
            else{
                updateStopCall($usrid, String.valueOf(ficaseid), paras.getStoptype(), paras.getStopcasemode(),
                        paras.getStopdays(), paras.getReason(), paras.getApplydsc());

            }
            ret++;
        }
        return new CmdResVo(ret);
    }



    @Override
    @Transactional
    public CmdResVo fiStopCustomerListAdd(String $usrid, StopCustomerListReqVo reqVo) {
        int ret=0;
        for (String cuId : reqVo.getCustomerList()) {
            if(JPubUtils.IsEmpty(cuId)) continue;
            updateStopCall($usrid, cuId.trim(),"CUSTOMER",null,
                    reqVo.getStopdays(),reqVo.getReason(),reqVo.getApplydsc());

            //获取当前客户下的案件
            caseStopList($usrid,cuId,reqVo.getReason(),reqVo.getApplydsc(),
                    reqVo.getStopdays());//案件进行停催

            customerStop(cuId,$usrid);//更新客户标识


            FiStopcall fiStopcall=selectJoinOne(FiStopcall.class,
                    new MPJLambdaWrapper<FiStopcall>()
                            .eq(FiStopcall::getStopkey,cuId)
                            .eq(FiStopcall::getStoptype,"CUSTOMER")
                            .in(FiStopcall::getStatus,EnumConfirmStatus.New.value,
                                    EnumConfirmStatus.Pending.value,
                                    EnumConfirmStatus.Pass.value)
            );

//            log.info("fiStopcall:{}",fiStopcall);
            //相同的案件或号码正在审核中
//            if(fiStopcall!=null) {
//                if (fiStopcall.getStatus() == EnumConfirmStatus.Pending.value) {
//                    throw new ServiceException(EnumRCode.DataPending.value, EnumRCode.DataPending.name);
//                }
//                else if(fiStopcall.getStatus() == EnumConfirmStatus.New.value ||
//                        fiStopcall.getStatus() == EnumConfirmStatus.Pass.value){
//                    throw new ServiceException(EnumRCode.DataProcess.value, EnumRCode.DataProcess.name);
//                }
//            }


            String clid="SYS_STOPCALL"; //此任务是系统配置任务，不能delete

            Integer wfid=cpCalllistService.getCalllistWfID(clid);

            int stopid=0;
            if(fiStopcall!=null) {
                stopid=fiStopcall.getStopid();
            }

            if(wfid>0){
                FiStopcall fi = new FiStopcall();
                //wfid=0 表示此任务clid没有配置工作流，前台可以根据是否有wfid显示不通的审批流程或状态
//                String status=fiWorkFlowCase.doCreate($usrid,wfid,stopid,tasknumber);
                String status=fiWorkFlowCase.doCreate($usrid,wfid,stopid,null);
                fi.setStopid(stopid);
                fi.setClid(clid);
                fi.setStatus(Integer.parseInt(status)); //处理中
                baseMapper.updateById(fi);
            }

            ret++;
        }
        return new CmdResVo(ret);
    }



    public void caseStopList(String $usrid,
                             String cuId,
                             String reason,
                             String applydsc,
                             Integer stopdays){
        List<FiCreditcases> fiCreditcases = fiCreditcasesMapper.selectList(new QueryWrapper<FiCreditcases>()
                .select("creditcaseid",
                        "customernumber",
                        "ccc")
                .eq("customernumber", cuId)
//         //       .in("ccc","O","Q")
        );
        for (FiCreditcases fiCreditcase : fiCreditcases) {
            //进行案件停催
            updateStopCall($usrid, String.valueOf(fiCreditcase.getCreditcaseid()),"CASE",null,
                    stopdays,reason,applydsc);
            SetFiCaseStopCall($usrid,fiCreditcase.getCreditcaseid());
        }
    }

    private void customerStop(String cuId,String $userid){

        log.info("userId:{},cuId:{}",$userid,cuId);
         ConCustomer conCustomer=new ConCustomer();
         conCustomer.setCustomernumber(cuId);
         conCustomer.setIsurgecust("1");
         conCustomer.setLastmodifieddate(new Date());
         conCustomer.setLastmodifiedby($userid);
         conCustomerMapper.updateById(conCustomer);
    }

    private void SetFiCaseStopCall(String $usrid,Integer ficaseid)
    {
        FiCreditcases fi=fiCreditcasesMapper.selectById(ficaseid);
        if( fi == null) return;
        //fi.setCreditcaseid(ficaseid);
        fi.setCcc(EnumFiCaseQueue.S.value);
        fi.setMddt(new Date());
        fi.setMdusr($usrid);
        if(ObjectUtils.isNotNull(fi.getRecycleType()) && fi.getRecycleType() >= 1000 && StringUtils.isNotEmpty(fi.getSendtodept())){
            caseRecycleByStop($usrid, fi);
        }
        else {
            fiCreditcasesMapper.updateById(fi);
        }
    }
    private void SetFiCustomerStopCall(String $usrid,String customernumber)
    {
        List<FiCreditcases> fis=fiCreditcasesMapper.selectList(
                new LambdaQueryWrapper<FiCreditcases>()
                        .eq(FiCreditcases::getCustomernumber,customernumber)
        );
        for(FiCreditcases fi : fis) {
            fi.setCreditcaseid(fi.getCreditcaseid());
            fi.setCcc(EnumFiCaseQueue.S.value);
            fi.setMddt(new Date());
            fi.setMdusr($usrid);
            //回收。
            if( ObjectUtils.isNotNull(fi.getRecycleType()) && fi.getRecycleType() >= 1000 && StringUtils.isNotEmpty(fi.getSendtodept())){
                caseRecycleByStop($usrid, fi);
            }
            else {
                fiCreditcasesMapper.updateById(fi);
            }
        }
    }
    private void caseRecycleByStop(String $usrid, FiCreditcases fi)
    {
        if(fi.getStatus().equals(EnumFiCaseStatus.Distribute.value) ||
                fi.getStatus().equals(EnumFiCaseStatus.Assign.value))
        {
            fi.setStatus(EnumFiCaseStatus.Recycle.value);
            fi.setStatusdt(new Date());
        }
        fi.setRecycleusr("system");
        fi.setRecycledt(new Date());
        fi.setRecycledsc("停催强制回收");

        FiCreditcasesHist fiCreditcasesHist = new FiCreditcasesHist();
        // 将属性复制到新对象中
        BeanUtils.copyProperties(fi, fiCreditcasesHist);
        fiCreditcasesHist.setActiontype(3); //回收
        fiCreditcasesHistMapper.insert(fiCreditcasesHist);
        fiCreditcasesMapper.update(fi,new UpdateWrapper<FiCreditcases>()
                .lambda()
                .eq(FiCreditcases::getCreditcaseid,fi.getCreditcaseid())
                .set(FiCreditcases::getSendtousr,null)
                .set(FiCreditcases::getAppointdt,null)
                .set(FiCreditcases::getAssignbatchid,null)
                .set(FiCreditcases::getAssignid,null)
                .set(FiCreditcases::getAssigntype,null)
                .set(FiCreditcases::getAssignusr,null)
                .set(FiCreditcases::getAssigndt,null)
                .set(FiCreditcases::getSendtodept,null)
                .set(FiCreditcases::getBindenddt,null)
                .set(FiCreditcases::getDistusr,null)
                .set(FiCreditcases::getDistdt,null)
                .set(FiCreditcases::getDistbatchid,null)
                .set(FiCreditcases::getDistributetype,null)
                .set(FiCreditcases::getDistributorid,null)
                .set(FiCreditcases::getLastccdt,null)
                .set(FiCreditcases::getLastcctaskid,null)
        );
    }
    private void SetFiCaseStopCallEnd(String $usrid,Integer ficaseid)
    {
        FiCreditcases fi=fiCreditcasesMapper.selectById(ficaseid);
        if( fi == null)
            return;
        //fi.setCreditcaseid(ficaseid);
        Integer status=fi.getStatus();
        if(status == EnumFiCaseStatus.New.value || status == EnumFiCaseStatus.Recycle.value || status == EnumFiCaseStatus.Return.value)
        {
            if( StringUtils.isNotEmpty(fi.getSendtodept()))
                fi.setCcc(EnumFiCaseQueue.Q.value);
            else
                fi.setCcc(EnumFiCaseQueue.O.value);
        }
        else if(status== EnumFiCaseStatus.Distribute.value || status==EnumFiCaseStatus.Assign.value){
            if( StringUtils.isNotEmpty(fi.getSendtodept()))
                fi.setCcc(EnumFiCaseQueue.Q.value);
            else {
                fi.setCcc(EnumFiCaseQueue.O.value);
                fi.setStatus(EnumFiCaseStatus.New.value);
                fi.setStatusdt(new Date());
            }
        }
        else if(status==EnumFiCaseStatus.Finish.value ){
            if(StringUtils.isNotEmpty(fi.getSendtodept()))
                fi.setCcc(EnumFiCaseQueue.Q.value);
            else
                fi.setCcc(EnumFiCaseQueue.R.value);
        }
        else if(status == EnumFiCaseStatus.Notice.value)
        {
            fi.setCcc(EnumFiCaseQueue.W.value);
        }
        fi.setMddt(new Date());
        fi.setMdusr($usrid);
        fiCreditcasesMapper.updateById(fi);
    }
    private void SetFiCustomerStopCallEnd(String $usrid,String cuId){
//        log.info("$usrid:{},cuId:{}",$usrid,cuId);
        ConCustomer conCustomer=new ConCustomer();
        conCustomer.setCustomernumber(cuId);
        conCustomer.setIsurgecust("0");
        conCustomer.setLastmodifieddate(new Date());
        conCustomer.setLastmodifiedby($usrid);
        conCustomerMapper.updateById(conCustomer);

        // 获取底下 停催案件
        List<FiCreditcases> fiCreditcases = fiCreditcasesMapper.selectList(new QueryWrapper<FiCreditcases>()
                .select("creditcaseid",
                        "customernumber",
                        "ccc")
                .eq("customernumber", cuId)
                .eq("ccc","S")
        );

        for (FiCreditcases fiCreditcase : fiCreditcases) {
            SetFiCaseStopCallEnd($usrid,fiCreditcase.getCreditcaseid());
        }

    }
}




